package com.cwz.controller;

import com.sun.deploy.net.HttpResponse;
import kong.unirest.Unirest;
import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wenZhen
 * @create 2025-02-13 17:50
 */
@RestController
@Slf4j
@RequestMapping("/chat")
public class ChatController {


    @PostMapping("/completions")
    public HttpResponse completions(String content){
        JSONObject requestBody = new JSONObject();
        JSONArray messages = new JSONArray();
        JSONObject message = new JSONObject();
        message.put("content", content);
        message.put("role", "user");
        messages.put(message);
        requestBody.put("messages", messages);
        requestBody.put("model", "deepseek-ai/DeepSeek-V3");

        return (HttpResponse) Unirest.post("https://api.siliconflow.cn/v1/chat/completions")
                .header("Authorization", "Bearer sk-qfhhbraztlakshzbswuoebktxbtzdbnnoyoqwkgqbtvwevhe")
                .header("Content-Type", "application/json")
                .body(requestBody.toString())
                .asString();
    }

}
